<script>
	export default {
		globalData: {
			unreadMessageCount: 0,
		},
		data() {
		        return {
		            jyJPush: []
		        };
		    },
		onLaunch: function() {
			console.log('App Launch')
			// #ifdef APP-PLUS
			// 锁定屏幕方向
			plus.screen.lockOrientation('portrait-primary');
			// 禁止截屏
			// if (plus.os.name == 'Android') {
			// 	var mainActivity = plus.android.runtimeMainActivity();
			// 	var win = plus.android.invoke(mainActivity, 'getWindow');
			// 	plus.android.invoke(win, 'addFlags', 0x00002000);
			// }
			// 检测升级
			let versionCode = parseInt(plus.runtime.versionCode);
			let versionString = plus.runtime.version;
			let versionArray = versionString.split('.');
			let versionBuild = 0;
			for (let i = 0; i < versionArray.length; i++) {
				let multiple = Math.pow(10, versionArray.length-1-i);
				versionBuild += versionArray[i]*multiple;
			}
			this.$api.api.ajaxData({
				method: 'V3.Update',
				versionid: plus.runtime.appid,
				version: versionCode,
				versionbuild: versionBuild,
			}, res => {
				if (res.status) {
					if (res.data.update && !!res.data.wgtUrl) {
						uni.downloadFile({
							url: res.data.wgtUrl,
							success: downloadResult => {  
								if (downloadResult.statusCode === 200) { 
									plus.runtime.install(downloadResult.tempFilePath, {
										force: false
									}, widgetInfo => {
										console.log(widgetInfo);
										plus.runtime.restart();
									}, err => {
										console.error(err);
									});
								}
							}
						});
					}
					if (res.data.update && !!res.data.pkgUrl) {
						uni.showModal({
							title: '更新提示',
							content: '有新版本更新~',
							success: res1 => {
								if (res1.confirm) {
									plus.runtime.openURL(res.data.pkgUrl);
									plus.runtime.quit();
								} else {
									plus.runtime.quit();
								}
							}
						})
					}
				}
			}, err => {
				console.log('----------网络错误，请检查网络----------')
			})
			// #endif
			// 极光推送
			this.jyJPush = uni.requireNativePlugin('JY-JPush');
			this.jyJPush.addJYJPushReceiveNotificationListener(result => {});
			this.jyJPush.addJYJPushReceiveOpenNotificationListener(result => {});
			// 判断是否有敏感词缓存,没有就请求接口
		    const sensitive = uni.getStorageSync('sensitive');
		    if (!sensitive) {
		    	// 调取查询邀请码是否强制接口
		    	this.$api.api.ajaxData({
		    		method: 'V1.SensitiveWord',
		    	}, res => {
		    		if (res.status) {
						
		    			uni.setStorage({
		    			    key: 'sensitive',
		    			    data: res.data.data,
		    			    success: function () {
		    			         // console.log('敏感词缓存成功');
		    			    }
		    			});
		    		}
		    	})
		    }
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		onError: function(e) {
			console.error('==========>App Error', JSON.stringify(e))
		},
		onUniNViewMessage: function (e) {
			console.log('==========>App UniNViewMessage', JSON.stringify(e))  
		}
	}
</script>

<style lang="scss">
	@import './common/common.scss';
	/* #ifdef APP-PLUS-NVUE */
	@import './common/uni-nvue.css';
	.btn-primary {
		background-image: linear-gradient(to right bottom, $main-color, $secondary-color);
		border-width: 0;
	}
	/* #endif */
	/* #ifndef APP-PLUS-NVUE */
	@import './common/uni.css';
	page {
		background-color: $page-bg-color;
	}
	button[type=primary]::after{
		border: none;
	}
	button[type=primary] {
		background-image: linear-gradient(to right bottom, $main-color, $secondary-color);
		background-color: transparent;
	}
	button[type=primary]:active {
		// background-image: linear-gradient(to left top, $main-color, $secondary-color);
	}
	
	button[type=primary][disabled] {
		background-image: none;
		background-color: #ccc !important;
	}
	button[type=default]::after{
		border: none;
	}
	.status-bar {
		width: 100%;
		height: var(--status-bar-height);
	}
	::-webkit-scrollbar {  
		display: none;  
		width: 0 !important;  
		height: 0 !important;  
		-webkit-appearance: none;
		background: transparent;
	}
	input {
		color: $title-color;
	}
	.empty-wrap {
		display: flex;
		width: 100%;
	}
	/* #endif */
	.empty-wrap {
		flex-direction: column;
		justify-content: center;
		align-items: center;
		padding: 50rpx 0;
	}
	.empty-icon {
		width: 200rpx;
		height: 200rpx;
	}
	.empty-text {
		font-size: 24rpx;
		color: $text-color;
		margin-top: 10rpx;
	}
	// checkbox的样式
	.uni-checkbox-input {
        border-radius: 50%;
        width: 18px !important;
        height: 18px !important;
        border: 1px solid #77be6e !important;
    }

    .uni-checkbox-input.uni-checkbox-input-checked {
        background-color: #77be6e;
        border: 1px solid #77be6e  !important;
        color: white !important;
    }

    .uni-checkbox-wrapper {
        width: 100%;
    }
</style>
